package cn.kgc.shiro02.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author: mosin
 * @version: v1.0  2022/6/1
 */
@Controller
@RequestMapping("role")
public class RoleController {

    @RequestMapping("add")
    @ResponseBody
    public  String addRole(){

        Subject subject = SecurityUtils.getSubject();

        if (subject.hasRole("admin")) {
            System.out.println("添加角色的方法被调用");
            return "添加角色成功";
        }
        return "没有访问权限";
    }

    @RequestMapping("select")
    @ResponseBody
    public  String selectRole(){
        System.out.println("查询角色的方法被调用");
        return "查询成功";
    }


    @RequestMapping("delete")
    @ResponseBody
    @RequiresRoles({"admin"})
    public  String deleteRole(){
        System.out.println("删除的方法被调用!");
        return "删除成功";
    }
}
